<template>
  <div class="clearfix">
    <div class="leftTop">
      <!-- <div class="letTopTitle" style="color: #545c75">添加功能</div> -->
      <el-button type="primary" plain @click="addFunc" size="mini"><img src="../../../assets/images/addess.png" style="width:10px;height:10px" alt=""> 添加功能</el-button>
    </div>
    <el-table
      :data="tableData"
      stripe
      style="width: 100%; overflow-x: auto !important"
    >
      <el-table-column prop="date" label="序号" width="180"> </el-table-column>
      <el-table-column prop="name" label="功能名称" width="180">
      </el-table-column>
      <el-table-column prop="address" label="功能类型" width="180">
      </el-table-column>
      <el-table-column prop="address" label="指向" width="180">
      </el-table-column>
      <el-table-column prop="address" label="当前状态" width="180">
      </el-table-column>
      <el-table-column prop="address" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="enable(scope.row)">启用</el-button>
          <el-button type="text" @click="set(scope.row)">修改</el-button>
          <el-button type="text" size="small" @click="del(scope.row)">删除</el-button>
          <el-button type="text" size="small" @click="top(scope.row)">上移</el-button>
          <el-button type="text" size="small" @click="bot(scope.row)">下移</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 弹框 -->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="431px"
      :before-close="handleClose"
    >
      <div>
        <div class="funcList">
          <div class="title">功能名称：</div>
          <el-input
            v-model="input"
            class="inputLength"
            placeholder="请输入内容"
          ></el-input>
        </div>
        <div class="funcList">
          <div class="title">跳转链接：</div>
          <el-input
            v-model="input"
            class="inputLength"
            placeholder="请输入内容"
          ></el-input>
        </div>
        <div class="funcList1">
          <div class="title">上传图标：</div>
          <div class="uploadIcon">
            <p style="margin-bottom: 20px">
              （ 尺寸 90px*90px，图片大小建议不超过80KB）
            </p>
            <el-upload
              :action="httpurl + '/api/fileUpload'"
              list-type="picture-card"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove"
              :before-upload="beforeAvatarUpload"
              :class="{ hide: hideUpload }"
              :on-change="picChange"
            >
              <i class="el-icon-plus"></i>
            </el-upload>
            <el-dialog :visible.sync="dialogVisible1" append-to-body>
              <img width="100%" :src="dialogImageUrl" alt="" />
            </el-dialog>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      hideUpload: false, //控制是否展示上传按钮
      dialogVisible: false,
      dialogVisible1: false,
      httpurl: this.GLOBAL.httpurl,
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1517 弄",
          zip: 200333,
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1519 弄",
          zip: 200333,
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1516 弄",
          zip: 200333,
        },
      ],
    };
  },
  methods: {
    picChange(file, fileList) {
      this.hideUpload = fileList.length >= 1;
    },
    addFunc() {
      this.dialogVisible = true;
    },
    handleRemove(file, fileList) {
      this.hideUpload = fileList.length >= 1;
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible1 = true;
    },
    // 上传图片类目
    beforeAvatarUpload(file) {
      const isJPG =
        file.type === "image/jpeg" ||
        file.type === "image/png" ||
        file.type === "image/jpg";
      if (!isJPG) {
        this.$message.error("只能上传图片");
      }
      const isSize = new Promise((resolve, reject) => {
        const width = 90;
        const height = 90;
        const _URL = window.URL || window.webkitURL;
        const img = new Image();
        img.onload = () => {
          const valid = img.width == width && img.height == height;
          valid ? resolve() : reject();
        };
        img.src = _URL.createObjectURL(file);
      }).then(
        () => {
          return file;
        },
        () => {
          layer.open({
            content: "图片尺寸限制为90 x 90",
            skin: "msg",
            time: 2, //1秒后自动关闭
          });
          // this.$notify({title: "错误",message: ,type: "error"});
          return Promise.reject();
        }
      );
      return isJPG && isSize;
    },
  },
};
</script>

<style scoped>
.funcList {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}
.funcList1 {
  display: flex;
}
/deep/ .inputLength {
  width: 300px;
}
/deep/ .inputLength .el-input__inner {
  width: 100% !important;
}
/deep/ .el-upload-list__item {
  transition: none !important;
}
/*  */
.titles {
  font-weight: bold;
  text-align: center;
  padding: 10px 0;
  width: 100%;
}
/deep/ .el-icon-plus{
  color: #409EFF;
  font-weight: bold;
}
.cont {
  background: rgb(246, 246, 246);
  height: 100%;
  padding: 0 20px;
  box-sizing: border-box;
  margin: 0 auto;
  padding-top: 10px;
}
.phoneBannere {
  background: #ccc;
  height: 150px;
  margin-bottom: 10px;
}
.moneys {
  margin: 4px 0;
}
.yuan {
  font-size: 22px;
  font-weight: 600;
  color: rgb(238, 96, 88);
}
.first {
  display: inline-block;
  margin-right: 20px;
}
.profit {
  background: white;
  border-radius: 5px;
  box-sizing: border-box;
  padding: 8px;
}
.phoneMenu {
  background: white;
  margin-top: 20px;
  border-radius: 5px;
  box-sizing: border-box;
  padding: 8px;
  margin-bottom: 20px;
}
.subList {
  width: 60px;
  height: 60px;
  margin-bottom: 20px;
}
.menuList {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
.pic {
  width: 50px;
  height: 50px;
  background: red;
  border-radius: 50%;
  margin: 0 auto;
}
.picTitle {
  text-align: center;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

.leftTop {
  display: flex;
  justify-content: space-between;
  margin-top: 15px;
  margin-bottom: 15px;
  box-sizing: border-box;
  padding: 0 20px;
}
.clearfix:after {
  display: block;
  height: 0;
  clear: both;
  content: ".";
  visibility: hidden;
}
</style>